package br.ucb.ucblive.beans;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;



@Entity
@Table (name="disciplina")
public class Disciplina {
	private int idDisciplina;
	private String nome;
	private String semestre;
	private String resumo;
	private Collection<Curso> disciplinaCurso;
	private Collection<Professor> disciplinaProfessor;
	private Collection<Topico> topicos;
	
	public Disciplina(){}

	@Id
	@GeneratedValue
	public int getIdDisciplina() {
		return idDisciplina;
	}

	public void setIdDisciplina(int idDisciplina) {
		this.idDisciplina = idDisciplina;
	}

	@Column
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	@Column
	public String getSemestre() {
		return semestre;
	}

	public void setSemestre(String semestre) {
		this.semestre = semestre;
	}

	@Column
	public String getResumo() {
		return resumo;
	}

	public void setResumo(String resumo) {
		this.resumo = resumo;
	}

	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	 @JoinTable(name = "disciplinaCurso",
	  joinColumns = @JoinColumn(name = "idDisciplina"), inverseJoinColumns = @JoinColumn(name = "idCurso"))
	public Collection<Curso> getDisciplinaCurso() {
		return disciplinaCurso;
	}

	public void setDisciplinaCurso(Collection<Curso> disciplinaCurso) {
		this.disciplinaCurso = disciplinaCurso;
	}
	
	
	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	 @JoinTable(name = "disciplinaProfessor",
	  joinColumns = @JoinColumn(name = "idDisciplina"), inverseJoinColumns = @JoinColumn(name = "idProfessor"))
	public Collection<Professor> getDisciplinaProfessor() {
		return disciplinaProfessor;
	}

	public void setDisciplinaProfessor(Collection<Professor> disciplinaProfessor) {
		this.disciplinaProfessor = disciplinaProfessor;
	}

	@OneToMany(mappedBy="disciplina")
	public Collection<Topico> getTopicos() {
		return topicos;
	}

	public void setTopicos(Collection<Topico> topicos) {
		this.topicos = topicos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idDisciplina;
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result + ((resumo == null) ? 0 : resumo.hashCode());
		result = prime * result
				+ ((semestre == null) ? 0 : semestre.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Disciplina other = (Disciplina) obj;
		if (idDisciplina != other.idDisciplina)
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (resumo == null) {
			if (other.resumo != null)
				return false;
		} else if (!resumo.equals(other.resumo))
			return false;
		if (semestre == null) {
			if (other.semestre != null)
				return false;
		} else if (!semestre.equals(other.semestre))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Disciplina [idDisciplina=" + idDisciplina + ", nome=" + nome
				+ ", semestre=" + semestre + ", resumo=" + resumo
				+ ", disciplinaCurso=" + disciplinaCurso
				+ ", disciplinaProfessor=" + disciplinaProfessor + "]";
	}
}
